﻿//-----------------------------------------------------------------------
// <copyright file="GroupMessageFilter.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.UI.MessageFilters
{
    using DomainObjects.XmlFeedObjects;

    using ChatBox.UI.Windows.PrivateMessages;

    /// <summary>
    /// Filter messages by group
    /// </summary>
    public class GroupMessageFilter : IMessageFilter
    {
        /// <summary>
        ///  the group filter data
        /// </summary>
        private GroupFilterSelection groupFilterSelection;

        /// <summary>
        /// Initializes a new instance of the GroupMessageFilter class
        /// </summary>
        /// <param name="groupFilterSelection">the group filter data</param>
        public GroupMessageFilter(GroupFilterSelection groupFilterSelection)
        {
            this.groupFilterSelection = groupFilterSelection;
        }

        /// <summary>
        /// test if the message is included by the filter
        /// </summary>
        /// <param name="message">the message to test</param>
        /// <returns>true if the message matches</returns>
        public bool IsIncluded(Message message)
        {
            switch (this.groupFilterSelection.GroupFilterType)
            {
                case GroupFilterType.ShowAllMessages:
                    return true;

                case GroupFilterType.ShowAllMessagesNotToAnyGroup:
                    return message.Group == null;

                case GroupFilterType.ShowAllMessagesToAnyGroup:
                    return message.Group != null;

                case GroupFilterType.ShowMessagesToGroup:
                    return (message.Group != null) && (message.Group.NodeId == this.groupFilterSelection.NodeId);
                    
                default:
                    return false;
            }
        }
    }
}
